(* args_manager.ml - Manage shell arguments.
 * Licence: LGPLv3
 * Authors: Franck "kushou" Michea < michea_f@epita.fr >
 *)

let fobj name =
  let tri = try Parser.obj2triangles name with Sys_error _ -> [] in
  let heights = try Parser.parse_heights name with Sys_error _ -> [] in
  Grapheng.set_objs tri;
  Grapheng.set_heights heights;
  Grapheng.main ()

let args =
  let g = "Display the image in grey." in
  let e = "Display the edges of the image." in
  let iw = "Display image with edges." in
  let gw = "Display grey image with edges." in
  let gr =  "Show vertices grid on the image." in
  let rh = "Input heights of the image. Writes an [image].heigths.txt file." in
  let obj =  "Save the *.obj file." in
  let ss = "Show processing step by step."
  in [("--grey", Arg.Unit (Process.add (Types.ImageType Types.Grey)), g);
      ("--edges", Arg.Unit (Process.add (Types.ImageType Types.Edges)), e);
      ("--iwedges", Arg.Unit (Process.add (Types.ImageType Types.IWEdges)), iw);
      ("--gwedges", Arg.Unit (Process.add (Types.ImageType Types.GWEdges)), gw);
      ("--request-heights", Arg.Unit(Process.add(Types.ImageType Types.RH)),rh);
      ("--show-steps", Arg.Unit (Process.add Types.ShowSteps), ss);
      ("--grid", Arg.Unit (Process.add (Types.ImageType Types.Grid)),gr);
      ("--to-obj", Arg.Unit (Process.add (Types.ImageType Types.Obj)),obj);
      ("--from-obj", Arg.String fobj, "Open and display an *.obj file.")]

let parse_args () =
  let name = "Fear fo the Map - 2D to 3D maps generator."
  in Arg.parse args Image.load name
